<template>
    <div>
        <el-card style="max-width: 480px">
            <template #header>
                <div class="card-header">
                    <span>管理系统</span>
                </div>
            </template>
            <el-form  style="max-width: 400px">
                <el-form-item label="用户名：">
                    <el-input v-model="username" type="text"></el-input>
                </el-form-item>
                <el-form-item label="密码：">
                    <el-input v-model="password" type="password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="login">登录</el-button>
                    <el-button @click="zhu">注册</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";

const username = ref('');
const password = ref('');

const router = useRouter();

const login = () => {
    if (username.value === "admin" && password.value === "123456") {
         localStorage.setItem("token","天王盖地虎")//模拟令牌
        router.replace({ path: "/home" });
        ElMessage({
            message: '登录成功',
            type: 'success',
        });
    } else {
        ElMessage({
            message: '登录失败',
            type: 'warning',
        });
    }
};

</script>

<style scoped>
.el-card {
    margin: 300px auto;
}
</style>    